<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
    require_once("class.connectSQL.inc");
    
    //instancia da classe
    $banco = new connectSQL();
	$banco1 = new connectSQL();
	$banco2 = new connectSQL();
	$banco3 = new connectSQL();
	$banco4 = new connectSQL();
	
?>

	<head>
    <?php include "head.php"; ?>
    <script>
    function validar(form){
   
    return true;
	}
    </script>
	</head>
	<body>
    	<!-- Header -->
       <?php include "sair.php"; ?>
            
            <!-- Header. Main part -->
            <div id="header-main">
                <div class="container_12">
                    <div class="grid_12">
                        <div id="logo">
                            <ul id="nav">
                                <li id="current"><a href="">PRODUTO</a></li>
                                
                            </ul>
                        </div><!-- End. #Logo -->
                    </div><!-- End. .grid_12-->
                    <div style="clear: both;"></div>
                </div><!-- End. .container_12 -->
            </div> <!-- End #header-main -->
            <div style="clear: both;"></div>
            <!-- Sub navigation -->
          
        </div> <!-- End #header -->
        
		<div class="container_12" align="center" >
        

            <div class="module">
                     <h2><span>Busca  de Produtos</span></h2>
                        
                     <div class="module-body">
                        <form action="buscaprod.php" onsubmit="return validar(this);" id="form" method="post">
                        
                            
                           
                          
                            <?php
							 	
							
					 	 if(isset($_GET["altera"])){
							 $resultado = $banco2->Query("SELECT * FROM estprod where codProd = ".$_GET["cod"]);
							 foreach ($resultado as $resut){
								$desc =  $resut['codBarProd'];
								$desc1 =  $resut['desProd'];
								$desc2 =  $resut['codMarc'];
							 }
						 }else{
							 	$desc = "";
								$desc1 = "";
						  } 
						  $resultado = $banco->Query("SELECT * FROM estmarc");
				?>
                            <p align="left">
                                <label>Código de Barras</label>
                                <input type="text" class="input-medium" id="codBarProd" name="codBarProd" value="" />
                                
                            </p>
                            
                            <p align="left">
                                <label>Nome</label>
                                <input type="text" class="input-medium" id="desProd" name="desProd" value="" />
                            </p>
                            <p align="left">	
                                <label>Marca</label>
                                <select class="input-medium" name="codmarc" id="codmarc">
                                <option value="">Selecione uma marca</option>
                                 <?php
		
										foreach ($resultado as $resut){
											$codMarc = $resut['codMarc'];
											if($desc2 == $codMarc ){
												echo "<option value='".$codMarc."' selected>".$resut['desMarca']."</option>";
											}else{
												echo "<option value=".$codMarc." >".$resut['desMarca']."</option>";
											}
												
											
										
										}
		?>
                               </select>
                            </p>
                             <p align="left">
                                <label>Todos</label>
                                <input type="checkbox"  id="todos" name="todos" value="" />
                            </p>
                            <fieldset>
                                <input class="submit-green" type="submit" value="Buscar" /> 
                                <input class="submit-gray" type="reset" value="Cancelar" />
                            </fieldset>
                        </form>
                     </div> <!-- End .module-body -->
					 
                </div>  <!-- End .module -->
				<?php 
				if(isset($msg)){
				echo "<span class='notification n-success'>".$msg."</span>";
				}
				?>
				
				
                     
        
                <!-- Example table -->
                <div class="module">
                	<h2>Produtos</h2>
                    
                    <div class="module-table-body">
                    	<form action="">
                        <table id="myTable" class="tablesorter">
                        	
                                <tr>
                                    <th style="width:5%">#</th>
                                    <th style="width:20%">Nome</th>
                                    <th style="width:20%">Marca</th>
                                    <th style="width:20%">Cód. Barras</th>
                                    <th style="width:15%"></th>
                                </tr>
                            
                            <tbody>
                           
                           <?php
						   
						   
					if(isset($_POST["codBarProd"])){
						$where = "";
						if($_POST["codBarProd"]>0){
							$where = " A.codBarProd = '".$_POST["codBarProd"]."' ";
						}
						
						if($_POST["desProd"]<>""){
							if($where <> ""){
								$where =  $where." and A.desProd like '%".$_POST["desProd"]."%' ";
							}else{
								$where = " A.desProd like '%".$_POST["desProd"]."%' ";
								}
						}
						
						if($_POST["codmarc"]<>""){
							if($where <> ""){
								$where = $where." and B.codmarc = '".$_POST["codmarc"]."' ";
							}else{
								$where = " B.codmarc = '".$_POST["codmarc"]."' ";
								}
						}
						
						if($where <> ""){
							$where = " where ".$where;	
						}
						
						if(isset($_POST["todos"])){
								$where = "";
							}
						
					}else{
						$where = " LIMIT 0 , 0";
						}					   
						   
						   if(isset($_GET["where"])){
							   $where = $_GET["where"];
							   }
						   
						   $resultado1 = $banco4->Query("SELECT B.desMarca,A.codProd,A.codBarProd,A.desProd FROM estprod as A inner join estmarc as B on A.codMarc = B.codMarc ".$where);
						   foreach ($resultado1 as $resut){
						   ?>
         <td> <?php echo $resut['codProd']; ?> </td>
         <td> <?php echo $resut['desProd']; ?> </td>
         <td> <?php echo $resut['desMarca']; ?> </td>  
         <td> <?php echo $resut['codBarProd']; ?> </td>                        
        <td><a href="cadprod.php?altera=1&cod=<?php echo $resut['codProd']; ?>"><img src="pencil.gif" tppabs="http://www.xooom.pl/work/magicadmin/images/pencil.gif" width="30" height="30" alt="edit" /></a><a href="cadprod.php?excluir=1&cod=<?php echo $resut['codProd']; ?>&where=<?php echo $where; ?>"><img src="bin.gif" tppabs="http://www.xooom.pl/work/magicadmin/images/bin.gif" width="30" height="30" alt="delete" /></a>
        <?php  
            
  		echo "</tr>";
		
   		        }          ?>  
                                
                                             
                     
                     
                      </tbody>
                        </table>
                        </form>
                     
                     
                 </div>    
                     
                     
            <div style="clear:both;"></div>
            
            <div style="clear:both;"></div>
        </div> <!-- End .container_12 -->
		
           
      
       <?php include "footer.php"; ?>
	</body>
</html>